Namespace CNG
    Public Class Distribuidor
        Private _CodigoCD As String
        Private _Codigo As Integer
        Private _Nombre As String
        Private _Activo As Boolean
        Private _Chofer As String
        Private _Telefono As String
        Public Property CodigoCD() As String
            Get
                Return _CodigoCD
            End Get
            Set(ByVal value As String)
                _CodigoCD = value
            End Set
        End Property
        Public Property Codigo() As Integer
            Get
                Return _Codigo
            End Get
            Set(ByVal value As Integer)
                _Codigo = value
            End Set
        End Property

        Public Property Nombre() As String
            Get
                Return _Nombre
            End Get
            Set(ByVal value As String)
                _Nombre = value
            End Set
        End Property
        Public Property Activo() As Boolean
            Get
                Return _Activo
            End Get
            Set(ByVal value As Boolean)
                _Activo = value
            End Set
        End Property
        Public Property Chofer() As String
            Get
                Return _Chofer
            End Get
            Set(ByVal value As String)
                _Chofer = value
            End Set
        End Property
        Public Property Telefono() As String
            Get
                Return _Telefono
            End Get
            Set(ByVal value As String)

                _Telefono = Value
            End Set
        End Property

        Public Sub Agregar()

            Dim comando As New CAD.Distribuidor.Distribuidor_INSERT(CAD.BaseDatos.Conexion)

            comando.ExecuteNonQuery(Me.CodigoCD, _
                                    Me.Codigo, _
                                    Me.Nombre, _
                                    Me.Activo, _
                                    Me.Chofer, _
                                    Me.Telefono)

        End Sub

        Public Sub Modificar()

            Dim comando As New CAD.Distribuidor.Distribuidor_UPDATE(CAD.BaseDatos.Conexion)



            comando.ExecuteNonQuery(Me.CodigoCD, _
                                    Me.Codigo, _
                                    Me.Nombre, _
                                    Me.Activo, _
                                    Me.Chofer, _
                                    Me.Telefono)
        End Sub

        Public Shared Function GenerarCodigo(ByVal CodigoCD As String) As Integer

            Dim Comando As New CAD.Distribuidor.Distribuidor_NEW_CODE(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable

            Comando.LoadTable(Tabla, CodigoCD)

            Return Tabla.Rows(0).Item("Codigo")

        End Function

        Public Shared Function ListadoDistribuidor(ByVal CodigoCD As String, ByVal Codigo As System.Nullable(Of Integer)) As DataTable

            Dim Comando As New CAD.Distribuidor.Distribuidor_SELECT(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable

            Comando.LoadTable(Tabla, CodigoCD, Codigo)

            Return Tabla

        End Function
        Public Shared Function GetDistribuidor(ByVal CodigoCD As String, ByVal Codigo As Integer) As Distribuidor

            Dim Comando As New CAD.Distribuidor.Distribuidor_SELECT(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable
            Dim miDistribuidor As New CNG.Distribuidor

            Comando.LoadTable(Tabla, CodigoCD, Codigo)

            If Tabla.Rows.Count > 0 Then

                miDistribuidor.CodigoCD = Tabla.Rows(0).Item("CodigoCD")
                miDistribuidor.Codigo = Tabla.Rows(0).Item("Codigo")
                miDistribuidor.Nombre = Tabla.Rows(0).Item("Nombre")
                miDistribuidor.Activo = Tabla.Rows(0).Item("Activo")
                miDistribuidor.Chofer = Tabla.Rows(0).Item("Chofer")
                miDistribuidor.Telefono = Tabla.Rows(0).Item("Telefono")

                Return miDistribuidor

            Else
                Return Nothing
            End If

        End Function
    End Class
End Namespace
